<template>
  <div>
    <router-link to="/seckill/add">
      <el-button type="primary">
      <i class="el-icon-circle-plus-outline"></i> 添加秒杀
    </el-button>
    </router-link>
    <div class="table-box">
      <el-table :data="list"  style="width: 100%">
        <el-table-column align="center" prop="title" label="活动名称" ></el-table-column>
        <el-table-column align="center" prop="begintime" label="开始时间" >
            <template slot-scope="scope">{{ scope.row.begintime*1 | toTime }}</template>
        </el-table-column>
        <el-table-column align="center" prop="endtime" label="结束时间" >
            <template slot-scope="scope">{{ scope.row.endtime*1 | toTime }}</template>
        </el-table-column>
        <el-table-column align="center"  prop="status" label="状态" >
          <template slot-scope="scope">
              <el-tag type="success" v-if="scope.row.status">已启用</el-tag>
              <el-tag type="info" v-else>已禁用</el-tag>  
          </template>
        </el-table-column>
        <el-table-column label="操作"  align="center">
              <template slot-scope="scope">
                    <router-link :to="'/seckill/'+scope.row.id"><el-button type="success" icon="el-icon-edit" size="mini" circle  ></el-button></router-link>
                    <el-button type="danger" icon="el-icon-delete" size="mini" @click="delRow(scope.row.id)" circle></el-button>
              </template>
          </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
// 获取数据、删除数据
import { getSeckill,delSeckill } from "@/request/seckill"
export default {
    data(){
        return{
            list:[],
        }
    },
    created(){
        this.getlist();  // 获取列表
    },
    methods:{
        async getlist(){
            this.list = await getSeckill();  
        },
        delRow(id){  // 删除某一条数据，接收删除的ID
            // 弹框确认！
            this.$confirm('确定删除吗, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                // 删除功能！
                await delSeckill(id);
                this.getlist();
            })
        }
    },
    components:{
    }
}
</script>
<style scoped>
.picimg{
    width:60px;
    border:1px solid #eee;
}
</style>